<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<script type="text/javascript">
function initLogs()
{
	jgrouse.log.addHandler(new jgrouse.logHandlers.ConsoleLog());
}

jgrouse_config = 
{
	initLogs : initLogs,
	logLevel : 'INFO',
	nologs : false,
	debug : true
}
</script>

<script type="text/javascript" src='../src/jgrouse.js'></script>
<script type="text/javascript" src='../src/log.js'></script>
<script type="text/javascript" src='../src/classloader.js'></script>
<script type="text/javascript" src='../src/jsunit.js'></script>


<script type="text/javascript">


jgrouse.module(
{
	name:'testMVC', 
	requires:['jgrouse.util.MvcDriver'], 
	imports : ['jgrouse.util.MvcDriver', 'jgrouse.util.PropertyChangeSupport'],  
	body:function(salt)
	{
		eval(salt);
	
		testMVC = {};
	
	
		jgrouse.define('testMVC.SampleView', 'jgrouse.BaseObject', function(salt)
		{
			eval(salt);
			
			
			return {
				initialize : function()
				{
					_super(this, 'initialize');
					this._triggered = {};
					this._pcs = new PropertyChangeSupport(this);
					this._others = {};
				},
				
				setPropertyOne : function(value)
				{
					this._propertyOne = value;
				},
				
				setPropertyTwo : function(value)
				{
					this._propertyTwo = value;
				},
				
				setPropertyThree : function(value)
				{
					this._propertyThree = value;
				},
				
				onPropertyChanged : function(event)
				{
					this._others[event.getPropertyName()] = event.getNewValue();
				},
				
				doMagic : function(value)
				{
					this._pcs.firePropertyChange('magic', value);
				}
			}
		});
		
		jgrouse.define('testMVC.SampleController', 'jgrouse.BaseObject', function(salt)
		{
			eval(salt);
			
			return {
				initialize : function()
				{
					this._data = null;
				},
				
				setData : function(value)
				{
					this._data = value;
					this._data.property2 = 'Hehehe';
				},
				
				setMagic : function(value)
				{
					this._data.property1 = value + 'Magic';
				}
			}
		});
	},
	
	postInit : function(embed)
	{
		eval(embed);
		eval(jgrouse.getImportString('jgrouse.jsunit.*'));
	
		jgrouse.delegate(testMVC.SampleView.prototype, '_pcs', PropertyChangeSupport.prototype);
	
		testMVC.run = function()
		{
			 controller = new testMVC.SampleController();
			 mvc = new MvcDriver(controller);
			 view = new testMVC.SampleView();
			
			mvc.bind(view, 'propertyOne', 'property1');
			mvc.bind(view, 'propertyTwo', 'property2');
			mvc.bind(view, 'propertyThree', 'property3');
			mvc.bind(view, 'propertySix', 'propertyEks');
			mvc.bind(view, 'magic', 'magic');
			
			var data = 
			{
				property1 : 'banzai',
				property2 : 'bebebe'
			}
			
			mvc.setData(data);
			assertEqual(view._propertyOne, 'banzai');
			view.doMagic('babah!');
			mvc.setProperty('property3', 'noonoo');
			mvc.setProperty('propertyEks', 'babah!');
			assertEqual(view._propertyOne, 'babah!Magic');
			assertEqual(view._propertyTwo, 'Hehehe');
			assertEqual(view._propertyThree, 'noonoo');
			assertEqual(view._others.propertySix, 'babah!');
			
		}
	}
});



</script>
</head>

<body>
This is a collection of unit tests for MVCDriver component
<div id="result"></div>
</body>
<script type="text/javascript">
		jgrouse.require('testMVC', function()
		{
			var ok = false;
			var e = '';
			try
			{
				testMVC.run();
				ok = true;
			}
			catch (ex)
			{
				e = ex.toString();
			}
			finally
			{
				document.getElementById('result').innerHTML = ok? 'Tests complete' : 'Tests failed:' + e;
			}
		});
</script>
</html>